/* -----------------------------------------------------------------------
 * Include the following lines in your makefile:
 *
 * unittest1: cardtest1.c dominion.o rngs.o
 *      gcc -o cardtest1 -g  cardtest1.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

#define PLAY_CARD smithy
#define PLAY_CARD_STR "smithy"

int main() {
    int r, handCount, handPos = 0, choice1 = 0, choice2 = 0, choice3 = 0;
    int numPlayer = 2;
    int seed = 1000;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    int deckCount = 5;
    int cardChange = 3;
    int player_hand[maxHandCount];
    int preDeckCount, preHandCount;
    int postDeckCount, postHandCount;

        player_hand[0] = PLAY_CARD;
        player_hand[1] = copper;
        player_hand[2] = copper;
        player_hand[3] = estate;
        player_hand[4] = estate;

#if (NOISY_TEST == 1)                  
    printf ("TESTING %s card:\n", PLAY_CARD_STR);      
#endif

        for (handCount = 1; handCount <= maxHandCount; handCount++)
    {
#if (NOISY_TEST == 1)
                printf("Test player with card hand count of %d.\n",handCount);
#endif
                memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                G.handCount[0] = handCount;                 // set the number of cards on hand
                memcpy(G.hand[0], player_hand, sizeof(int) * handCount); // set all the cards to player_hand
                preDeckCount = G.deckCount[0];
                preHandCount = G.handCount[0];
               
                // play the card in position 0 (smithy)        
                r = playCard(handPos,choice1,choice2,choice3,&G);
                postDeckCount = G.deckCount[0];
                postHandCount = G.handCount[0];        

#if (NOISY_TEST == 1)
        printf("Pre deck count = %d, Post deck count = %d, expected = %d.\n", preDeckCount, postDeckCount, deckCount - cardChange);
        printf("Pre hand count = %d, Post hand count = %d, expected = %d.\n", preHandCount, postHandCount, handCount -1 + cardChange);
#endif                                  
               
                assert(postDeckCount == deckCount - cardChange);
                assert(postHandCount == handCount -1 + cardChange);
               
        }
   
    printf("Smithy effect passed!\n");
       
    return 0;
}
